var mongoose = require('mongoose');
var multer  = require('multer');
var upload = require('../models/upload.model');
var path = require('path')


exports.filedata = function(req,res,next){
   
    var storage = multer.diskStorage({
        destination : function(req, file , cb){
            cb(null,'uploads/')
        },
        filename:function(req,file,cb){
            cb(null,file.filename +'-'+Date.now() + path.extname(file.originalname))
        }
    })
    var upload = multer({storage:storage }).single('avatar');
    upload(req,res,function(err){
        var file = req.file;
        console.log(file)
        console.log('文件类型：%s', file.mimetype);
        console.log('原始文件名：%s', file.originalname);
        console.log('文件大小：%s', file.size);
        console.log('文件保存路径：%s', file.path);
        //  var uploads = new Upload(req.file);
        // // uploads.save
        // uploads.save(function (err,data) {
        //     if (err) {
        //       console.log(err);
        //     } else {
        //       res.json(data);
        //     }
        //   });
    })

}